<%@language=vbscript%>
<%
	Session("FormName")="F19"
	Session("bChucnang")=13
	Session("VanBan")=""
%>
<!--#include file="..\CheckSession.inc"-->
<!--#include file="..\pageSelected.inc"-->
<!--#include file=..\getFormName.inc-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="vi">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
</head>
<!--#include file="..\RootContent.inc"-->
<!--#include file="..\jvGrid.inc"-->
<%	
	bhienthi="1"
	bComm=Request("bComm")
'Hien15_06
	bIDVTDen=Request("bIDVTDen")
	bID=Request("bID")
	bNgayHTXL=Request("bNgayHTXL")
	bNam=request("bNam")
	bsoghinhan=Request("bsoghinhan")
' HienSX	
	sort=request("sort")

	if sort="" then sort="RevDate"
	Select case sort
		Case "Date":
			oSQL=" order by ngayky,so,soghinhan"
			bImgDate="../Images/up.gif"
			bImgSymbol=""
			bImgSubject=""
		Case "RevDate":
			oSQL=" order by ngayky DESC,so DESC,soghinhan DESC"
			bImgDate="../Images/down.gif"
			bImgSymbol=""
			bImgSubject=""
		Case "Symbol":
			oSQL=" order by so,soghinhan,ngayky"
			bImgDate=""
			bImgSymbol="../Images/up.gif"
			bImgSubject=""
		Case "RevSymbol":
			oSQL=" order by so DESC,soghinhan DESC,ngayky DESC"
			bImgDate=""
			bImgSymbol="../Images/down.gif"
			bImgSubject=""
		Case "Subject":
			oSQL=" order by Trichyeu,ngayky,so,soghinhan"
			bImgDate=""
			bImgSymbol=""
			bImgSubject="../Images/up.gif"
		Case "RevSubject":
			oSQL=" order by Trichyeu DESC,ngayky DESC,so DESC,soghinhan DESC"
			bImgDate=""
			bImgSymbol=""
			bImgSubject="../Images/down.gif"
		Case "Attach":
			oSQL=" order by attach"
			bImgDate=""
			bImgNum=""
			bImgSymbol=""
			bImgSubject=""		
		Case "RevAttach":
			oSQL=" order by attach DESC"
			bImgDate=""
			bImgNum=""
			bImgSymbol=""
			bImgSubject=""
	End Select
Select case bComm
	case "Okadd"
		sSQL="delete HoanThanhXL where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=0"
		Conn.Execute sSQL
		sSQL="Select * from hoanthanhxl where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
		Set RecCheck=Server.CreateObject("ADODB.Recordset")
		RecCheck.CursorType=3
		RecCheck.CacheSize=5
		RecCheck.Open sSQL,Conn
		if RecCheck.RecordCount>0 then
			bidvtdi=RecCheck("idvtdi")
			bsgn=RecCheck("kqxl")
			if bidvtdi="" then
				bidvtdi=bID
			else
				bidvtdi=bidvtdi+"$"+bID
			end if
			if bsgn="" then
				bsgn=bsoghinhan
			else
				bsgn=bsgn+", "+trim(bsoghinhan)
			end if
			sSQl="update HoanThanhXL set idvtdi='"& bidvtdi &"',NgayHTXL='"& SaveDate(bNgayHTXL) &"',kqxl='"& bsgn &"' where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
			Conn.Execute sSQL
		else
			sSQL="insert into HoanThanhXL(IDVTDen,IDVTDi,NgayHTXL,Madonvi,kqxl,trangthai) values ('"& bIDVTDen &"','"& bID &"','"& SaveDate(bNgayHTXL) &"','"& Session("bMaDonVi") &"','"& trim(bsoghinhan) &"',1)"
			Conn.Execute sSQL
		end if
		RecCheck.close
		set RecCheck=nothing
	case "Delete"
		sSQL="delete HoanThanhXL where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=0"
		Conn.Execute sSQL
		sSQL="Select * from hoanthanhxl where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
		Set RecCheck=Server.CreateObject("ADODB.Recordset")
		RecCheck.CursorType=3
		RecCheck.CacheSize=5
		RecCheck.Open sSQL,Conn
		if RecCheck.RecordCount>0 then
			bsgn=LoaiID(RecCheck("kqxl"),bsoghinhan)
			bidvtdi=LoaiID(RecCheck("idvtdi"),bID)
			if bidvtdi="" then
				sSQL="delete HoanThanhXL where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
				Conn.Execute sSQL
			else
				sSQl="update HoanThanhXL set idvtdi='"& bidvtdi &"',NgayHTXL='"& SaveDate(bNgayHTXL) &"',kqxl='"& bsgn &"' where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
			Conn.Execute sSQL
			end if
		end if
		RecCheck.close
		set RecCheck=nothing
	end select
	sSQL="Select * from hoanthanhxl where IDVTDen ='" & modistring(bIDVTDen) & "'and  Madonvi='"& Session("bMaDonVi") &"' and trangthai=1"
	Set RecVtdi=Server.CreateObject("ADODB.Recordset")
	RecVtdi.CursorType=3
	RecVtdi.CacheSize=5
	RecVtdi.Open sSQL,Conn
	if RecVtdi.RecordCount>0 then
		bcheckidvtdi=RecVtdi("idvtdi")
	end if
	RecVtdi.close
	set RecVtdi=nothing

	if bcomm="search" then
		bSoghinhan=request("TxtSogoc")
		bID=request("TxtID")
		bTukhoa=trim(Request("TxtTukhoa"))
		bTungay=Request("TxtTungay")
		bDenngay=Request("TxtDenNgay")
		bTrichyeu=trim(Request("TxtTrichyeu"))
		'bgphucth 08-01-03
			if bTrichyeu="" and bTukhoa="" and bSoghinhan="" and bID="" and bNhomCV="" then
				if bTungay=bDenngay then
					bNgayIn=bTungay
				end if
			end if
		'edphucth 08-01-03
		bTimCX=trim(Request("chkTimCX"))
		if bTimCX ="" then		
			strChar="%"
		else	' Tim Chinh Xac
			strChar=""
		end if
		bTungay=Request("TxtTungay")
		bDenngay=Request("TxtDenngay")
		bSKH=Request("TxtSKH")
		bTrichyeu=trim(Request("TxtTrichyeu"))
		bND=trim(Request("TxtND"))
		bDonvisoan=trim(Request("select1"))
		'bNoinhan=trim(Request("select2"))
		bNoinhan=trim(Request("TxtNoinhan"))
		bComboLoaiVB=Request("ComboLoaiVB")
		bTukhoa=trim(Request("TxtTukhoa"))
		bNguoiky=Request("TxtNguoiky")
		bDiso=request("TxtDenso")
		bSodi=request("TxtSoDen")
		bNam=trim(Request("TxtNam"))
		bLoai=Request("bLoai")

		sDieuKien=""
		if trim(bTungay)<> "" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And ngayky >= '"& SaveDate(bTungay) &"' "
			else
				sDieuKien=" ngayky >= '"& SaveDate(bTungay) &"' "
			end if
			Session("VTDiFrom")=bTungay
		end if

		if trim(bDenngay)<> "" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And ngayky <= '"& SaveDate(bDenngay) &"' "
			else
				sDieuKien=" ngayky <= '"& SaveDate(bDenngay) &"' "
			end if
			Session("VTDiTo")=bDenngay
		end if

		if bSKH<>"" then
			if sDieuKien <> "" then
			'	sDieuKien=sDieuKien + " And Soghinhan like '"& strChar &""& Modistring(bSKH) &"/%' "
				if strChar="" then
					sDieuKien=sDieuKien + " And Soghinhan like '"& Modistring(bSKH) & "/%'"
				else
					sDieuKien=sDieuKien + " And Soghinhan like '"& strChar & Modistring(bSKH) & "%'"
				end if
			else
			'	sDieuKien=" Soghinhan like '"& strChar &""& Modistring(bSKH) &"/%' "
				if strChar="" then
					sDieuKien=" Soghinhan like '"& Modistring(bSKH) & "/%'"
				else
					sDieuKien=" Soghinhan like '"& strChar & Modistring(bSKH) & "%'"
				end if
			end if
		end if

		if bDonvisoan<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And dvsoan Like '"& strChar &""& Modistring(bDonvisoan) &""& strChar &"' "
			else
				sDieuKien=" dvsoan Like '"& strChar &""& Modistring(bDonvisoan) &""& strChar &"' "
			end if
		end if

		if bNoinhan<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And (Noinhan Like '"& strChar &""& Modistring(bNoinhan) &""& strChar &"' OR Nguoinhan Like '"& strChar &""& Modistring(bNoinhan) &""& strChar &"')"
			else
				sDieuKien="(Noinhan Like '"& strChar &""& Modistring(bNoinhan) &""& strChar &"' OR Nguoinhan Like '"& strChar &""& Modistring(bNoinhan) &""& strChar &"')"
			end if
		end if

		if bTrichyeu<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And Trichyeu Like '"& strChar &""& Modistring(bTrichyeu) &""& strChar &"'"
			else
				sDieuKien=" Trichyeu Like '"& strChar &""& Modistring(bTrichyeu) &""& strChar &"'"
			end if
		end if
		if bND<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And Tomtat Like '"& strChar &""& Modistring(bND) &""& strChar &"' "
			else
				sDieuKien=" Tomtat Like '"& strChar &""& Modistring(bND) &""& strChar &"' "
			end if			
		end if
		if bComboLoaiVB<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And Phanloai = "& cstr(bComboLoaiVB) &" "
			else
				sDieuKien=" Phanloai = "& cstr(bComboLoaiVB) &" "
			end if			
		end if
		if bTukhoa<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And Tukhoa Like '"& strChar &""& Modistring(bTukhoa) &""& strChar &"' "
			else
				sDieuKien=" Tukhoa Like '"& strChar &""& Modistring(bTukhoa) &""& strChar &"' "
			end if			
		end if
		if bNguoiky<>"" then
			if sDieuKien <> "" then
				sDieuKien=sDieuKien + " And Nguoiky Like '"& strChar &""& Modistring(bNguoiky) &""& strChar &"' "
			else
				sDieuKien=" Nguoiky Like '"& strChar &""& Modistring(bNguoiky) &""& strChar &"' "
			end if
		end if
		if bSodi<>"" then
			if sDieuKien <> "" then			 
				sDieuKien=sDieuKien + " And So >= "& Modistring(bSodi) &" "
			else
				sDieuKien=" So >= "& Modistring(bSodi) &" "
			end if
		end if
		if bDiso<>"" then
			if sDieuKien <> "" then			 
				sDieuKien=sDieuKien + " And So <= "& Modistring(bDiso) &" "
			else
				sDieuKien=" So <= "& Modistring(bDiso) &" "
			end if
		end if
		if bNam<>"" then
			if sDieuKien <> "" then			 
				sDieuKien=sDieuKien + " And year(ngayky)='"& bNam &"' "
			else
				sDieuKien=" year(ngayky)='"& bNam &"' "
			end if
		end if

		if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then
			if sDieuKien<>"" then
				sSQL="Select " &session("TopNum")& " vtdi.* from VTDI where vtdi.trangthaiduyet=1 and " + sDieuKien
			else
				sSQL="Select " &session("TopNum")& " vtdi* from VTDI where vtdi.trangthaiduyet=1 and vtdi.ngaydi >= '"& Session("Year") &"'"
			end if
		else
			btcu="SELECT Quyen_Nhom.Mavanthu FROM Canbo INNER JOIN Canbo_Nhom ON Canbo.Macanbo =Canbo_Nhom.Macanbo INNER JOIN Nhom ON dbo.Canbo_Nhom.Manhom=Nhom.Manhom INNER JOIN Quyen_Nhom ON Nhom.Manhom =Quyen_Nhom.MaNhom WHERE (Canbo.Macanbo = '"& Session("bMaCB") &"') And Quyen_nhom.maloaivanthu like '2'"
			bt="SELECT Quyen_Nhom.Mavanthu FROM donvi inner join quyen_nhom on donvi.id = quyen_nhom.manhom where donvi.madonvi like '"& Session("bMaDonVi") &"' and Quyen_nhom.maloaivanthu like '2'"
			if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),4)="1" or Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" then
				if sDieuKien<>"" then
					sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and vtdi.trangthaiduyet=1 and " + sDieuKien 
				else
					sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and and vtdi.trangthaiduyet=1 and vtdi.ngaynhan >= '"& Session("Year") &"'"
				end if
			else
				if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),8)="1" then
					if sDieuKien<>"" then
						sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and vtdi.trangthaiduyet=1 and " + sDieuKien 
					else
						sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and vtdi.trangthaiduyet=1 and vtdi.ngaynhan >= '"& Session("Year") &"'"
					end if
				else
					if sDieuKien<>"" then
						sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2')))) and vtdi.trangthaiduyet=1 and " + sDieuKien 
					else
						sSQL="SELECT " &session("TopNum")& " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2')))) and vtdi.trangthaiduyet=1 and vtdi.ngaynhan >= '"& Session("Year") &"'"
					end if
				end if
			end if
		end if
		Session("sSQLDi")=sSQL
		sSQL=sSQL & oSQL
	else
		btcu="SELECT Quyen_Nhom.Mavanthu FROM Canbo INNER JOIN Canbo_Nhom ON Canbo.Macanbo =Canbo_Nhom.Macanbo INNER JOIN Nhom ON dbo.Canbo_Nhom.Manhom=Nhom.Manhom INNER JOIN Quyen_Nhom ON Nhom.Manhom =Quyen_Nhom.MaNhom WHERE (Canbo.Macanbo = '"& Session("bMaCB") &"') And Quyen_nhom.maloaivanthu like '2'"
		bt="SELECT Quyen_Nhom.Mavanthu FROM donvi inner join quyen_nhom on donvi.id = quyen_nhom.manhom where donvi.madonvi like '"& Session("bMaDonVi") &"' And Quyen_nhom.maloaivanthu like '2'"
		if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then 
			if session("sSQLDi")="" then
				sSQL="Select " & session("TopNum") & " vtdi.* from VTDI where vtdi.ngayky >= '"& Session("Year") &"' and vtdi.trangthaiduyet=1 " & oSQL
			else
				sSQL=session("sSQLDi") & oSQL
			end if
		else
			if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),4)="1" or Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),9)="1" then
				if session("sSQLDi")="" then
					sSQL="SELECT " & session("TopNum") & " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID  in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and vtdi.ngayky >= '"& Session("Year") &"' and vtdi.trangthaiduyet=1 " & oSQL
				else
					sSQL=session("sSQLDi") & oSQL
				end if
			else
				if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),8)="1" then
					if session("sSQLDi")="" then
						sSQL="SELECT " & session("TopNum") & " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and vtdi.donvixuly like '%"& Session("bMaDonVi") &"%') or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or (VTDI.Congcong=0 and ((VTDI.ID  in ("& bt &")) or (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2'))))) and vtdi.trangthaiduyet=1 and vtdi.ngayky >= '"& Session("Year") &"' and vtdi.trangthaiduyet=1 " & oSQL
					else
						sSQL=session("sSQLDi") & oSQL
					end if
				else
					if session("sSQLDi")="" then
						sSQL="SELECT " & session("TopNum") & " VTDI.* FROM VTDI WHERE ((VTDI.Congcong=1) or (VTDI.Congcong=0 and (VTDI.ID  in ("& btcu &"))) or  (VTDI.Congcong=0 and (VTDI.ID  in (Select mavanthu from Quyen where macanbo='"& Session("bMaCB") &"'  and maloaivanthu='2')))) and vtdi.trangthaiduyet=1 and vtdi.ngayky >= '"& Session("Year") &"' and vtdi.trangthaiduyet=1 " & oSQL
					else
						sSQL=session("sSQLDi") & oSQL
					end if
				end if
			end if
		end if
	end if
	Set Rec=server.CreateObject("ADODB.Recordset")
	Rec.CursorType=3
	Rec.CacheSize=5
	Dim nRecCount	' Number of records found
	Dim nPageCount	' Number of pages of records we have
	Dim nPage	' Current page number
	nPage=CLng(request("Page"))	
	if nPage="" then nPage=1
	rec.Open ssql,Conn
	if  rec.EOF and rec.BOF then
		nPageCount=0
	end if
	bDisplay=Request("bDisplay")
	if  bDisplay then
		sSQL="Select * from VTDi where ID like "& request("bID")
		Set RecDisplay=Server.CreateObject("ADODB.Recordset")
		RecDisplay.CursorType=3
		RecDisplay.CacheSize=5
		RecDisplay.Open sSQL,Conn
		if RecDisplay.RecordCount>0 then
			bSoghinhan=RecDisplay("Soghinhan")
			bID=RecDisplay("ID")
			bngayky=RecDisplay("ngayky")
			bTukhoa=RecDisplay("Tukhoa")
			bTrichyeu=RecDisplay("TRichyeu")
			bDuyet=RecDisplay("Trangthaiduyet")
			bChophep=RecDisplay("Congcong")
			Session("bTenVBdi")=RecDisplay("TRichyeu")
			sSQL="Select tentep from vanban_noidung where mavanthu like '"& bID &"' and Loaivanthu='2' order by Sothutu "
			Set RecVBND=server.CreateObject("ADODB.recordset")
			RecVBND.CursorType=3
			RecVBND.CacheSize=5
			RecVBND.Open sSQL,Conn
			if RecVBND.RecordCount>0 then
				bTenTep=RecVBND("tentep")
			end if
			
'			bTenTep=RecDisplay("Tentep")
		end if
		RecDisplay.Close
		set RecDisplay=nothing
		
		' Kiem tra quyen R/W/F
		if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),4)="1" or Session("IsAdmin") then
			bQuyen="F"
		else
			sSQL="Select * from Quyen Where Mavanthu like '"& bID &"' and Macanbo like '"& Session("bMaCB") &"' and maloaivanthu like '2'"
			Set RecKTQ=server.CreateObject("ADODB.Recordset")
			RecKTQ.CursorType=3
			RecKTQ.CacheSize=5
			RecKTQ.Open sSQL,Conn
			if RecKTQ.RecordCount>0 then
				bQuyen=RecKTQ("Quyen")
			end if
			RecKTQ.Close
			set RecKTQ=nothing
		end if
	end if

%>
<%	if request("chuachon")="thongtin" then%>
		<p align=center><font face=Arial color=red>B&#7841;n c&#7847;n ch&#7885;n &#273;&#250;ng th&#244;ng tin c&#7847;n s&#7917;a</font></p>
<%	end if
%>
<!--#include file="..\jvfunction.inc"-->
<script language=VBScript runat=server>
	' H&#224;m &#273;&#7883;nh d&#7841;ng l&#7841;i ng&#224;y M/D/Y-> D/M/Y
	Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function ModiString(mess_s)
		message = Replace("" & mess_s,"'", "''")
		ModiString=message
	End function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function
	Function LoaiID(strid,id)
		lenid=len(id)
		lenstrid=len(strid)
		i=0
		i=instr(1,strid,id)
		if i > 0 then
			if i+lenid >= lenstrid then
				LoaiID=mid(strid,1,i-2)
			else
				LoaiID=mid(strid,1,i-1)+mid(strid,i+lenid+1,lenstrid-i-lenid)
			end if
		else
			LoaiID=strid
		end if
	End Function
</script>	
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
//HienSX
function Sort(SortKey){
	if (document.Noidung.Sort.value.indexOf(SortKey)== -1)
		document.Noidung.Sort.value=SortKey;
	else {
		if (document.Noidung.Sort.value.indexOf('Rev')== -1)
			document.Noidung.Sort.value='Rev' + SortKey;
		else
			document.Noidung.Sort.value= SortKey;
	}
	Noidung.target="right";
	Noidung.action="frmSelectVTDi.asp?sort=" + Noidung.Sort.value;
	Noidung.submit();
}
function SetFocus(){
	window.Noidung.CmdSearch.focus();
}

function ChangePage(){
	strURL=Noidung.page.value;
	window.Noidung.target="right";
	window.Noidung.action=strURL;
	window.Noidung.submit();
}

function CmdSearch_onclick() {
	OpenW("");
	return;
	if(trim(Noidung.TxtTungay.value)!=""){
		if (!isDate(trim(Noidung.TxtTungay.value))){
			alert("Ngày không hợp lệ");
			Noidung.TxtTungay.focus();
			return false;
		}
		else
			if(trim(Noidung.TxtDenngay.value)==""){
				alert("Cho biết đến ngày");
				Noidung.TxtDenngay.focus();
				return false;
			}
	}
	if(trim(Noidung.TxtDenngay.value)!=""){	
		if (!isDate(trim(Noidung.TxtDenngay.value))){
			alert("Ngày không hợp lệ");
			Noidung.TxtDenngay.focus();
			return false;
		}
		else
			if(trim(Noidung.TxtTungay.value)==""){
				alert("Cho biết từ ngày");
				Noidung.TxtDenngay.focus();
				return false;
			}
	}
	window.Noidung.target="right";
	window.Noidung.action="frmSelectVTDi.asp?bComm=search";
	window.Noidung.submit();
}
function OpenW(bCom){
//HienSX
	sort=Noidung.Sort.value;
	remote = window.open('frmselectsearchDI.asp?sort='+sort+'&bComm=VTDI&bNgayHTXL=<%=bNgayHTXL%>&bIDVTDen=<%=bIDVTDen%>&bNam=<%=bNam%>','new_page','width=600,height=233,top=5,left=160').focus();
}
function CmdOK_onclick(){
	bidvtden=Noidung.bIDVTDen.value;
	bngayhtxl=Noidung.bNgayHTXL.value;
	window.Noidung.target="right";
	window.Noidung.action="frmSelectVTDi.asp?bComm=Okadd&bID="+"<%=bID%>"+"&bIDVTDen="+bidvtden+"&bNgayHTXL="+bngayhtxl+"&bsoghinhan="+"<%=bsoghinhan%>"+"&sort=" + Noidung.Sort.value;
	window.Noidung.submit();
}
function CmdLoaiBo_onclick(){
	bidvtden=Noidung.bIDVTDen.value;
	bngayhtxl=Noidung.bNgayHTXL.value;
	window.Noidung.target="right";
	window.Noidung.action="frmSelectVTDi.asp?bComm=Delete&bID="+"<%=bID%>"+"&bIDVTDen="+bidvtden+"&bNgayHTXL="+bngayhtxl+"&bsoghinhan="+"<%=bsoghinhan%>"+"&sort=" + Noidung.Sort.value;
	window.Noidung.submit();
}
function CmdExit_onclick(){
	window.Noidung.target="right";
	window.Noidung.action="<%=Session("tenvtden")%>";
	window.Noidung.submit();
}
//-->
</SCRIPT>
<LINK href="../styles/styles.css" type=text/css rel=STYLESHEET>
<body bgcolor=#F8F9D9 leftmargin=2 topmargin=0 onload="SetFocus()">
<%if bMsg<>"" then%>
	<p align=center><font color=red><%=bMsg%></p>
<%end if%>
<form name="Noidung" method="post">
<Input TYPE="hidden" name="Sort" value="<%=sort%>">
<Input TYPE="hidden" name="bIDVTDen" value="<%=bIDVTDen%>">
<Input TYPE="hidden" name="bNgayHTXL" value="<%=bNgayHTXL%>">
<Input type=hidden name=TxtSoghinhan value='<%=bSoghinhan%>'>
<Input type=hidden name=TxtID value="<%=bID%>">
<%Session("bMaVBDi")=bID%>
<!-- Form nhap lieu -->
<table border="0" width="100%" bgcolor="#BDD5D0" style="Font-family:Times New Roman;font-size:12pt;">
    <tr>
      <TD WIDTH="100%" BGCOLOR="#000080" ALIGN="CENTER"><FONT FACE='TIMES NEW ROMAN' COLOR="#FFFFFF" SIZE=2><B>DANH SÁCH CÔNG VĂN ĐI</B></FONT></TD>
    </tr>
  </table>
<!-- Buttons -->
<table border="0" width="100%" style="Font-family:Arial;font-size:10pt;" cellspacing=1 cellpadding=0 align=center>
	<tr>
	    <td width="25%">
			<Button name="CmdSearch" style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdSearch_onclick()" accesskey="m">Tì<u>m</u> kiếm</Button>
		</td>
	    <td width="25%">
			<%if bDisplay then%>
				<Button name="CmdOK" style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><u>G</u>hi nhận</Button>
			<%else%>
				<Button name="CmdOK" disabled style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><u>G</u>hi nhận</Button>
			<%end if%>
   		</td>
	    <td width="25%">
			<%if bDisplay then%>
				<Button name="CmdLoaibo" style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdLoaiBo_onclick()" accesskey="L"><u>L</u>oại bỏ</Button>
			<%else%>
				<Button name="CmdLoaibo" disabled style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdLoaiBo_onclick()" accesskey="L"><u>L</u>oại bỏ</Button>
			<%end if%>
   		</td>
	    <td width="25%">
			<Button name="CmdExit" style="height: 25; position: relative; width: 100%;font-family:Arial" LANGUAGE=javascript onclick="return CmdExit_onclick()" accesskey="y">Qua<u>y</u> lại</Button>
		</td>
	</tr>
</table>
<!-- Danh sach cong van di -->
  <table border="0" width="100%" style="Border-color:#C0C0C0;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid">
  <tr bgcolor="#BDD5D0">
	  <td width="4%"></td>
	  <td width="5%"></td>
      <td width="18%" nowrap><A onmouseover="window.status='';return true" HREF="javascript:Sort('Symbol')"><b>Số, ký hiệu</b>&nbsp;&nbsp;
	  <% if bImgSymbol<>"" then %><IMG SRC="<%=bImgSymbol%>" BORDER=0><%end if%>
	  </A></td>
      <td width="18%" nowrap><A onmouseover="window.status='';return true" HREF="javascript:Sort('Date')">&nbsp;<b>Ngày ký</b>&nbsp;&nbsp;
  	  <% if bImgDate<>"" then %><IMG SRC="<%=bImgDate%>" BORDER=0><%end if%>
	  </A></td>
      <td width="56%" nowrap><A onmouseover="window.status='';return true" HREF="javascript:Sort('Subject')">&nbsp;<b>Trích yếu</b>&nbsp;&nbsp;&nbsp;
	  <% if bImgSubject<>"" then %><IMG SRC="<%=bImgSubject%>" BORDER=0><%end if%>
	  </A></td>
   <% 
	If Not Rec.Eof Then
		nRecCount = Rec.RecordCount
		Rec.PageSize = 20
		nPageCount = Rec.PageCount
		If nPage < 1 then
			nPage = 1			
		End If
		if nPage > nPageCount Then
			nPage=nPageCount
		end if
		cnt=(pg-1)*pgsize + 1		    
		STT=1
		rec.AbsolutePage=nPage
		howmanyrecs=0
		btrangthai=""
		do while not Rec.EOF and howmanyrecs<rec.PageSize
			if (cnt/2=int(cnt/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if		
			ktvtdi=0
			ktvtdi=instr(1,bcheckidvtdi,Rec("id"))
			if ktvtdi > 0 then
				btrangthai="<IMG border=0 SRC=Tick.gif>"
			else
				btrangthai=""
			end if
%>
	<%if "'" & Rec("ID") & "'"=Request("bID") then
		color="#BDD7D6"
	end if
	%>	
	<%if rec("Trangthaiduyet") then%>
		<%if mid(rec("donvixuly"),2,4) <> mid(Session("bMaDonVi"),1,4) and bhienthi <> "1" and not(rec("congcong")) then%>
			<tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" 
	 onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
	    <td width="4%" align="center"><%=btrangthai%></td>
		<%Select case Rec("Tinhchat")
			case "01"%>
				<td width="5%" nowrap><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thuthuong.gif></p></a></td>
			<%case "02"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhan.gif></p></a></td>
			<%case "03"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thumat.gif></p></a></td>
			<%Case "04"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhanmat.gif></p></a></td>
		<%end select%>    
			<td width="18%"><a style='cursor:hand;color:grey;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("soghinhan")%></p></a></td>

			<td width="18%" ><a style='cursor:hand;color:grey;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="center"><%=FormatDate(Rec("ngayky"))%></p></a></td>

			<td width="56%"><a style='cursor:hand;color:grey;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("trichyeu")%></p></a></td>
		  </tr>	
		<%else%>
		  <tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" 
	 onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
	    <td width="4%" align="center"><%=btrangthai%></td>
		<%Select case Rec("Tinhchat")
			case "01"%>
				<td width="5%" nowrap><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thuthuong.gif></p></a></td>
			<%case "02"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhan.gif></p></a></td>
			<%case "03"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thumat.gif></p></a></td>
			<%Case "04"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhanmat.gif></p></a></td>
		<%end select%>               		
			<td width="18%"><a style='cursor:hand;color:blue;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("soghinhan")%></p></a></td>

			<td width="18%" ><a style='cursor:hand;color:blue;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="center"><%=FormatDate(Rec("ngayky"))%></p></a></td>

			<td width="56%"><a style='cursor:hand;color:blue;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("trichyeu")%></p></a></td>
		  </tr>
		  <%end if%>
      <%else%>
      <tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" 
 onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
 	    <td width="4%" align="center"><%=btrangthai%></td>
		<%Select case Rec("Tinhchat")
			case "01"%>
				<td width="5%" nowrap><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thuthuong.gif></p></a></td>
			<%case "02"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhan.gif></p></a></td>
			<%case "03"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thumat.gif></p></a></td>
			<%Case "04"%>
				<td width="5%" ><a href="xemnoidung.asp?LoaiVt=2&bMa=<%=Rec("ID")%>&bNam=<%=year(Rec("ngayky"))%>" target="_blank"><p align="center" title="Xem n&#7897;i dung v&#259;n th&#432;"><IMG border=0 SRC=Thukhanmat.gif></p></a></td>
		<%end select%>               
        <td width="18%"><a style='cursor:hand;color:red;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("soghinhan")%></p></a></td>

		<td width="18%"><a style='cursor:hand;color:red;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="center"><%=FormatDate(Rec("ngayky"))%></p></a></td>
        
		<td width="56%"><a style='cursor:hand;color:red;text-decoration: none' href="frmSelectVTDi.asp?bDisplay=True&page=<%=nPage%>&bID='<%=Rec("ID")%>'&bNam=<%=year(Rec("ngayky"))%>&bIDVTDen=<%=bIDVTDen%>&bNgayHTXL=<%=bNgayHTXL%>&bsoghinhan=<%=rec("soghinhan")%>"><p align="left"><%=Rec("trichyeu")%></p></a></td>
      </tr>
      <%end if%>
		<%
			if  Session("VanBan")="" then
				Session("VanBan")= "-" & Rec("ID") 
			else
				Session("VanBan")=Session("VanBan") & "-" & Rec("ID") 
			end if
		%>
<%		STT=STT+1
			Rec.MoveNext
			cnt=cnt+1
			howmanyrecs=howmanyrecs+1
	loop
		Session("VanBan")=Session("VanBan") & "-" 
	end if
	rec.Close
	set rec=nothing
%>
 </table>
 <!-- Phan trang -->
<br>
<table width="98%" cellspacing=0 cellpadding=0 >
<tr>
<% if nPage > 0 and nPageCount > 0 then %>  
	<td width="20%"><b>Trang&nbsp; <%=nPage%>/<%=nPageCount%></b></td>
	<td width= "80%" align="right">
	<% if nPageCount > 1 then %>    
		Chuyển nhanh tới trang:&nbsp;
		<select name="page" style="width:50;height:25;font-size:8pt" size=1 onchange="javaScript:ChangePage()">
			<% for i = 1 to nPageCount%>	
				<%	if bComm<>"search"  then
						strURL="frmSelectVTDi.asp?page="+ cstr(i) + "&bComm="
					else
						strURL="frmSelectVTDi.asp?page="+ cstr(i) + "&bComm=search &TxtSogoc=" +bSoghinhan+ "&TxtTungay=" +bTungay+ "&TxtDenngay=" +bdenngay+ "&TxtTukhoa=" +bTukhoa+ "&TxtTrichyeu=" +bTrichyeu
				end if %>
				<option value="<%=strURL%>" <%=chkSelected(i, nPage)%>><%=i%></option>
			<% next %>    
		</select>
		</td>                                  
	<% end if %>             
<% 'else %>
<% end if %>
  </tr>
</table>
</body>
</form>
</font>
</html>
<%
	Conn.Close
	set Conn=nothing
%>